//
//  ZXZRegisterViewController.m
//  sheyingzu
//
//  Created by tyu on 30.5.24.
//

#import "ZXZRegisterViewController.h"



@interface ZXZRegisterViewController ()<UITextViewDelegate,UIScrollViewDelegate>
@property(nonatomic,weak) UIScrollView *ScrollView;

@property(nonatomic,weak) UITextField *phoneTextF;
@property(nonatomic,weak) UITextField *CodeTextF;
@property(nonatomic,weak) UITextField *twoCodeTextF;


@end

@implementation ZXZRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}



- (void)bac_addUI
{
    [super bac_addUI];
    
    [self setupView];
    
    [self setupBottomView];
    
    [self.view bringSubviewToFront:self.navView];
    self.bacbBackBtn.hidden = YES;
    
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.view endEditing:YES];
    
}

- (void)setupView
{
    
    UIScrollView *ScrollV = [[UIScrollView alloc]init];
    [self.view addSubview:ScrollV];
    self.ScrollView =ScrollV;
    ScrollV.delegate = self;
    
    ScrollV.contentSize = CGSizeMake(ScreenWidth, ScreenHeight*1.1);
    ScrollV.contentInset = UIEdgeInsetsMake(0, 0, -10, 0);
    ScrollV.showsVerticalScrollIndicator = NO;
    ScrollV.frame = CGRectMake(0, 100, ScreenWidth, ScreenHeight-ShowDiff);
    
    
    CGFloat leftW = 30;
    
    
    UIButton *backBtn = [[UIButton alloc] init];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
    [self.ScrollView addSubview:backBtn];
    backBtn.frame = CGRectMake(30, 0, 25, 25);
    [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    UILabel *titLab = [UIView lableWithText:@"打开运动视界" andColor:[UIColor blackColor] andFont:16];
    [self.ScrollView addSubview:titLab];
    titLab.font = [UIFont boldSystemFontOfSize:26];
    titLab.frame = CGRectMake(leftW, CGRectGetMaxY(backBtn.frame)+70, ScreenWidth-60, 30);
    
    
    UITextField *phoneTextF = [UIView textfieldPlaceholder:@"请输入手机号" keyboardType:UIKeyboardTypeNumberPad];
    [ScrollV addSubview:phoneTextF];
    self.phoneTextF =phoneTextF;
    
    phoneTextF.frame = CGRectMake(leftW, CGRectGetMaxY(titLab.frame)+30, ScreenWidth-40, 40);
    
    
    UIView *phoneV = [[UIView alloc]init];
    [ScrollV addSubview:phoneV];
    phoneV.backgroundColor = [UIView ColorWithHexString:@"#F4F4F4"];
    phoneV.frame = CGRectMake(leftW, CGRectGetMaxY(phoneTextF.frame)+2, ScreenWidth-40, 1);
    
    
    UITextField *CodeTextF = [UIView textfieldPlaceholder:@"请输入密码,密码由至少6位数字或字母组成" keyboardType:UIKeyboardTypeNumberPad];
    [ScrollV addSubview:CodeTextF];
    self.CodeTextF =CodeTextF;
    CodeTextF.frame = CGRectMake(leftW, CGRectGetMaxY(phoneV.frame)+20, ScreenWidth-40, 40);
    
    UIView *codeV = [[UIView alloc]init];
    [ScrollV addSubview:codeV];
    codeV.backgroundColor = [UIView ColorWithHexString:@"#F4F4F4"];
    codeV.frame = CGRectMake(leftW, CGRectGetMaxY(CodeTextF.frame)+2, ScreenWidth-40, 1);
    
    
    
    UITextField *twoCodeTextF = [UIView textfieldPlaceholder:@"请再次输入密码" keyboardType:UIKeyboardTypeNumberPad];
    [ScrollV addSubview:twoCodeTextF];
    self.twoCodeTextF =twoCodeTextF;
    twoCodeTextF.frame = CGRectMake(leftW, CGRectGetMaxY(codeV.frame)+20, ScreenWidth-40, 40);
    
    UIView *twoCodeV = [[UIView alloc]init];
    [ScrollV addSubview:twoCodeV];
    twoCodeV.backgroundColor = [UIView ColorWithHexString:@"#F4F4F4"];
    twoCodeV.frame = CGRectMake(leftW, CGRectGetMaxY(twoCodeTextF.frame)+2, ScreenWidth-40, 1);
    
}



- (void)setupBottomView
{
    
    CGFloat leftW = 30;
    
    UIButton *loginBtn = [[UIButton alloc] init];
    [self.ScrollView addSubview:loginBtn];
    loginBtn.frame = CGRectMake(leftW, CGRectGetMaxY(self.twoCodeTextF.frame)+20, ScreenWidth-60, 44);
    
    [loginBtn addTarget:self action:@selector(loginBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [loginBtn setTitle:@"注册" forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    loginBtn.backgroundColor = [UIView ColorWithHexString:@"#07C6D2"];
    loginBtn.layer.cornerRadius = 44/2;
    loginBtn.layer.masksToBounds = YES;
    
    
}

- (void)loginBtnClick
{
    
    
    
    if (self.phoneTextF.text.length<=0) {
        [NotifyLabel NotifyWithString:@"请输入您的手机号"];
        return;
    }else if (self.phoneTextF.text.length <=10 ){
        [NotifyLabel NotifyWithString:@"请输入正确的手机号"];
        return;
    }else if (self.CodeTextF.text.length <=5 || self.CodeTextF.text.length <= 0){
        [NotifyLabel NotifyWithString:@"请输入您的密码,至少6位"];
        return;
        
    }else if (![self.twoCodeTextF.text isEqualToString:self.CodeTextF.text ]){
        [NotifyLabel NotifyWithString:@"两次输入的密码不一致"];
        return;
    }
    
    [userDef setValue:self.phoneTextF.text forKey:userName];
    [userDef setValue:self.twoCodeTextF.text forKey:userCode];
    
    [NotifyLabel NotifyWithString:@"注册成功"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self backBtnClick];
        
    });
    
}


- (void)backBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
